/*
   GRF allocation:
   g1~g30: constant buffer
           g1~g2:intra IQ matrix
           g3~g4:non intra IQ matrix
           g5~g20:IDCT tab
   g31:    read and write message descriptor
   g32~g55:DCT data
   g58~g81:reference data
   g82:    thread payload 
   g83~g106:IDCT data 
*/
mov (8) g82.0<1>UD g31.0<8,8,1>UD {align1};

mov.sat (16) g33.0<2>UB g33.0<16,16,1>W {align1};
mov.sat (16) g34.0<2>UB g34.0<16,16,1>W {align1};
mov.sat (16) g35.0<2>UB g35.0<16,16,1>W {align1};
mov.sat (16) g36.0<2>UB g36.0<16,16,1>W {align1};
mov.sat (16) g37.0<2>UB g37.0<16,16,1>W {align1};
mov.sat (16) g38.0<2>UB g38.0<16,16,1>W {align1};
mov.sat (16) g39.0<2>UB g39.0<16,16,1>W {align1};
mov.sat (16) g40.0<2>UB g40.0<16,16,1>W {align1};
mov.sat (16) g41.0<2>UB g41.0<16,16,1>W {align1};
mov.sat (16) g42.0<2>UB g42.0<16,16,1>W {align1};
mov.sat (16) g43.0<2>UB g43.0<16,16,1>W {align1};
mov.sat (16) g44.0<2>UB g44.0<16,16,1>W {align1};
mov.sat (16) g45.0<2>UB g45.0<16,16,1>W {align1};
mov.sat (16) g46.0<2>UB g46.0<16,16,1>W {align1};
mov.sat (16) g47.0<2>UB g47.0<16,16,1>W {align1};
mov.sat (16) g48.0<2>UB g48.0<16,16,1>W {align1};

mov.sat (16) g49.0<2>UB g49.0<16,16,1>W {align1};
mov.sat (16) g50.0<2>UB g50.0<16,16,1>W {align1};
mov.sat (16) g51.0<2>UB g51.0<16,16,1>W {align1};
mov.sat (16) g52.0<2>UB g52.0<16,16,1>W {align1};
mov.sat (16) g53.0<2>UB g53.0<16,16,1>W {align1};
mov.sat (16) g54.0<2>UB g54.0<16,16,1>W {align1};
mov.sat (16) g55.0<2>UB g55.0<16,16,1>W {align1};
mov.sat (16) g56.0<2>UB g56.0<16,16,1>W {align1};

mov (1) g31.8<1>UD 0x00F000FUD {align1};

and.nz (1) null g82.30<1,1,1>UB 0x1UW{align1};
(f0) jmpi field_dct_y;

mov (16) m1.0<1>UB  g33.0<16,16,2>UB {align1};
mov (16) m1.16<1>UB g34.0<16,16,2>UB {align1};
mov (16) m2.0<1>UB  g35.0<16,16,2>UB {align1};
mov (16) m2.16<1>UB g36.0<16,16,2>UB {align1};
mov (16) m3.0<1>UB  g37.0<16,16,2>UB {align1};
mov (16) m3.16<1>UB g38.0<16,16,2>UB {align1};
mov (16) m4.0<1>UB  g39.0<16,16,2>UB {align1};
mov (16) m4.16<1>UB g40.0<16,16,2>UB {align1};
mov (16) m5.0<1>UB  g41.0<16,16,2>UB {align1};
mov (16) m5.16<1>UB g42.0<16,16,2>UB {align1};
mov (16) m6.0<1>UB  g43.0<16,16,2>UB {align1};
mov (16) m6.16<1>UB g44.0<16,16,2>UB {align1};
mov (16) m7.0<1>UB  g45.0<16,16,2>UB {align1};
mov (16) m7.16<1>UB g46.0<16,16,2>UB {align1};
mov (16) m8.0<1>UB  g47.0<16,16,2>UB {align1};
mov (16) m8.16<1>UB g48.0<16,16,2>UB {align1};
jmpi write_back_y;

field_dct_y:
mov (16) m1.0<1>UB  g33.0<16,16,2>UB {align1};
mov (16) m1.16<1>UB g41.0<16,16,2>UB {align1};
mov (16) m2.0<1>UB  g34.0<16,16,2>UB {align1};
mov (16) m2.16<1>UB g42.0<16,16,2>UB {align1};
mov (16) m3.0<1>UB  g35.0<16,16,2>UB {align1};
mov (16) m3.16<1>UB g43.0<16,16,2>UB {align1};
mov (16) m4.0<1>UB  g36.0<16,16,2>UB {align1};
mov (16) m4.16<1>UB g44.0<16,16,2>UB {align1};
mov (16) m5.0<1>UB  g37.0<16,16,2>UB {align1};
mov (16) m5.16<1>UB g45.0<16,16,2>UB {align1};
mov (16) m6.0<1>UB  g38.0<16,16,2>UB {align1};
mov (16) m6.16<1>UB g46.0<16,16,2>UB {align1};
mov (16) m7.0<1>UB  g39.0<16,16,2>UB {align1};
mov (16) m7.16<1>UB g47.0<16,16,2>UB {align1};
mov (16) m8.0<1>UB  g40.0<16,16,2>UB {align1};
mov (16) m8.16<1>UB g48.0<16,16,2>UB {align1};

write_back_y:
send (16) 0 acc0<1>UW g31<8,8,1>UW write(0,0,2,0) mlen 9 rlen 0 {align1};

//U
mov (1) g31.8<1>UD 0x0070007UD  { align1 };
shr (2) g31.0<1>UD g82.0<2,2,1>UD 1D {align1};

mov (16) m1.0<1>UB  g49.0<16,16,2>UB {align1};
mov (16) m1.16<1>UB g50.0<16,16,2>UB {align1};
mov (16) m2.0<1>UB  g51.0<16,16,2>UB {align1};
mov (16) m2.16<1>UB g52.0<16,16,2>UB {align1};
send (16) 0 acc0<1>UW g31<8,8,1>UW write(1, 0, 2, 0) mlen 3 rlen 0 { align1 };

//V
mov (16) m1.0<1>UB  g53.0<16,16,2>UB {align1};
mov (16) m1.16<1>UB g54.0<16,16,2>UB {align1};
mov (16) m2.0<1>UB  g55.0<16,16,2>UB {align1};
mov (16) m2.16<1>UB g56.0<16,16,2>UB {align1};
send (16) 0 acc0<1>UW g31<8,8,1>UW write(2, 0, 2, 0) mlen 3 rlen 0 { align1 };

OUT:
send (16) 0 acc0<1>UW g0<8,8,1>UW
        thread_spawner(0, 0, 0) mlen 1 rlen 0 { align1 EOT};

